#!/bin/bash
#

#获取最近三天的日志
	#设置最近三天变量参数
	time0=`date +%F`
	time1=0
	time2=0

	#获取年月日
	Y=`echo $time0 | awk -F'-' '{print $1}'`
	m=`echo $time0 | awk -F'-' '{print $2}'`
	d=`echo $time0 | awk -F'-' '{print $3}'`
	
	#计算最近三天时间
	let y1=$d-1
	let y2=$d-2
	
	time1="$Y-$m-$y1"
	time2="$Y-$m-$y2"

#遍历日志目录
for i in `find /root/log/ -name "test*"`;do
	times=`echo $i | awk -F'test_' '{print $2}' | awk -F'.' '{print $1}'`
	DF=`echo $times | awk -F'_' '{print $2}'`
	#判断是否为其他格式日志
	if [ -z $DF ];then
		#判断是否为三天内的日志
		if [ $times != $time0 -a $times != $time1 -a $times != $time2 ];then
			file="test_${times}.log"
			rm -rf /root/log/$file
		fi
	else #其他格式日志处理
		timess=`echo $times|awk -F'_' '{print $1}'`
		#判断是否为三天内的日志
		if [ $timess != $time0 -a $timess != $time1 -a $timess != $time2 ];then
			file="test_${times}.log"
			rm -rf /root/log/$file
		fi
	fi
done 
